//logs.js
var app = getApp()
var user  = require('../../utils/user.js')
var util  = require('../../utils/util.js')
Page({
  data: {
    user:null,
    api_url: app.globalData.api_url,
  },
  onLoad:function(options){
      // wx.navigateTo({
      //   url: '/pages/user/index'
      // })
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成 
  },
  onShow:function(){
    // 页面显示
    if (user.checkLogin()) {
      this.setData({login:true})
    }else{
      this.setData({login:false})
    }
    var that = this
    user.getLoginUserInfo(function(res){
      that.setData({
        user:res.data
      })
      console.log(res.data)
    })
  },
  logout: function() {
    var that = this
    wx.showNavigationBarLoading()
    user.logout()
    that.setData({login:false})
    wx.hideNavigationBarLoading()
  },
  login:function(){
    wx.navigateTo({
      url: '/pages/login/login',
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
   },
  register:function(){
    wx.navigateTo({
      url: '/pages/register/index',
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
  }
})
